<!-- 功能：邮件报警 | 作者：menghao.yan | 邮箱：yxs2615@163.com | 时间：2023年08月22日 23:01:12 -->
<template>
  <a-tabs v-model:activeKey="activeKey" type="card" class="y-tabs">
    <a-tab-pane key="jieShouYouJianDiZhi" tab="接收邮件地址">
      <a-card>
        <a-row align="middle">
          <a-col :span="16">
            <a-space>
              <a-button type="link" class="y-btn" @click="openTianJiaJieShouYouJianDiZhiModal">
                <template #icon>
                  <plus-outlined />
                </template>
                添加接收邮件地址
              </a-button>
              <!-- 弹窗 - 添加接收邮件地址 -->
              <tianJiaJieShouYouXiangDiZhiModal v-model:visible="visibleTianJiaJieShouYouJianDiZhiModal"></tianJiaJieShouYouXiangDiZhiModal>
            </a-space>
          </a-col>
          <a-col :span="8">
            <a-input v-model:value="searchValueJieShouYouJianDiZhi">
              <template #addonBefore>
                <search-outlined /> 搜索:
              </template>
            </a-input>
          </a-col>
        </a-row>
        <a-table bordered :data-source="dataSourceJieShouYouJianDiZhi" :columns="columnsJieShouYouJianDiZhi" class="y-table" :pagination="paginationJieShouYouJianDiZhi">
        </a-table>
      </a-card>
    </a-tab-pane>

    <a-tab-pane key="baoJingYouJianFaSongFuWuQi" tab="报警邮件发送服务器">
      <a-card>
        <a-row align="middle">
          <a-col :span="16">
            <a-space>
              <a-button type="link" class="y-btn" @click="openTianJiaBaoJingYouJianFaSongFuWuQiModal">
                <template #icon>
                  <plus-outlined />
                </template>
                添加报警邮件发送服务器
              </a-button>
              <!-- 弹窗 - 添加报警邮件发送服务器 -->
              <tianJiaBaoJingYouJianFaSongFuWuQiModal v-model:visible="visibleTianJiaBaoJingYouJianFaSongFuWuQiModal"></tianJiaBaoJingYouJianFaSongFuWuQiModal>
              <a-button type="link" class="y-btn" @click="ceShiBaoJingYouJianFaSongFuWuQi">
                <template #icon>
                  <plus-outlined />
                </template>
                测试报警邮件发送服务器
              </a-button>
            </a-space>
          </a-col>
          <a-col :span="8">
            <a-input v-model:value="searchValueBaoJingYouJianFaSongFuWuQi">
              <template #addonBefore>
                <search-outlined /> 搜索:
              </template>
            </a-input>
          </a-col>
        </a-row>
        <a-table bordered :data-source="dataSourceBaoJingYouJianFaSongFuWuQi" :columns="columnsBaoJingYouJianFaSongFuWuQi" class="y-table" :pagination="paginationBaoJingYouJianFaSongFuWuQi">
        </a-table>
      </a-card>
    </a-tab-pane>

  </a-tabs>
</template>

<script setup>
import tianJiaJieShouYouXiangDiZhiModal from './modal/tianJiaJieShouYouXiangDiZhiModal.vue'
import tianJiaBaoJingYouJianFaSongFuWuQiModal from './modal/tianJiaBaoJingYouJianFaSongFuWuQiModal.vue'
import { ExclamationCircleOutlined } from '@ant-design/icons-vue'
import { Modal } from 'ant-design-vue'
const activeKey = ref('jieShouYouJianDiZhi')

// -- 接收邮件地址
const visibleTianJiaJieShouYouJianDiZhiModal = ref(false)

const openTianJiaJieShouYouJianDiZhiModal = () => {
  visibleTianJiaJieShouYouJianDiZhiModal.value = true
}

const searchValueJieShouYouJianDiZhi = ref('')

// 表格列
const columnsJieShouYouJianDiZhi = ref([
  {
    title: '用户ID',
    dataIndex: 'id',
    key: 'name',
    align: 'center',
    sorter: {
      compare: (a, b) => a.id.localeCompare(b.id),
      multiple: 1
    }
  },
  {
    title: '用户名',
    dataIndex: 'userName',
    key: 'userName',
    align: 'center',
    sorter: {
      compare: (a, b) => a.userName.localeCompare(b.userName),
      multiple: 2
    }
  },
  {
    title: '接收邮件地址',
    dataIndex: 'emailAddress',
    key: 'emailAddress',
    align: 'center',
    sorter: {
      compare: (a, b) => a.emailAddress.localeCompare(b.emailAddress),
      multiple: 3
    }
  },
  {
    title: '启用',
    dataIndex: 'qiYong',
    key: 'qiYong',
    align: 'center',
    sorter: {
      compare: (a, b) => a.qiYong.localeCompare(b.qiYong),
      multiple: 4
    }
  }
])

// 表格数据
const dataSourceJieShouYouJianDiZhi = ref([
  {
    key: '1',
    id: '1',
    userName: '1',
    emailAddress: '1',
    qiYong: '1'
  },
  {
    key: '2',
    id: '2',
    userName: '2',
    emailAddress: '2',
    qiYong: '2'
  }
])

// 分页
const paginationJieShouYouJianDiZhi = {
  current: 1,
  pageSize: 10,
  showQuickJumper: true,
  showSizeChanger: true,
  total: 0,
  showTotal: (total, range) => {
    return `${range[0]}-${range[1]} 共 ${total} 条数据`
  },
  onChange: (page, pageSize) => {
    console.log('报警设置 > 邮件报警 >>', page, pageSize)
  }
}

// -- 报警邮件发送服务器
const visibleTianJiaBaoJingYouJianFaSongFuWuQiModal = ref(false)

const openTianJiaBaoJingYouJianFaSongFuWuQiModal = () => {
  visibleTianJiaBaoJingYouJianFaSongFuWuQiModal.value = true
}

const searchValueBaoJingYouJianFaSongFuWuQi = ref('')

// 表格列
const columnsBaoJingYouJianFaSongFuWuQi = ref([
  {
    title: '发送邮件地址',
    dataIndex: 'faSongYouJianDiZhi',
    key: 'faSongYouJianDiZhi',
    align: 'center',
    sorter: {
      compare: (a, b) => a.faSongYouJianDiZhi.localeCompare(b.faSongYouJianDiZhi),
      multiple: 1
    }
  },
  {
    title: '邮件发送服务器',
    dataIndex: 'youJianFaSongFuWuQi',
    key: 'youJianFaSongFuWuQi',
    align: 'center',
    sorter: {
      compare: (a, b) => a.youJianFaSongFuWuQi.localeCompare(b.youJianFaSongFuWuQi),
      multiple: 2
    }
  },
  {
    title: '身份验证',
    dataIndex: 'shenFenYanZheng',
    key: 'shenFenYanZheng',
    align: 'center',
    sorter: {
      compare: (a, b) => a.shenFenYanZheng.localeCompare(b.shenFenYanZheng),
      multiple: 3
    }
  },
  {
    title: '默认SMTP服务器',
    dataIndex: 'moRenSmtpFuWuQi',
    key: 'moRenSmtpFuWuQi',
    align: 'center',
    sorter: {
      compare: (a, b) => a.moRenSmtpFuWuQi.localeCompare(b.moRenSmtpFuWuQi),
      multiple: 4
    }
  }
])

// 表格数据
const dataSourceBaoJingYouJianFaSongFuWuQi = ref([
  {
    key: '1',
    faSongYouJianDiZhi: '123@qq.com',
    youJianFaSongFuWuQi: 'smtp.qq.com',
    shenFenYanZheng: 'true',
    moRenSmtpFuWuQi: '25'
  }
])

// 分页
const paginationBaoJingYouJianFaSongFuWuQi = {
  current: 1,
  pageSize: 10,
  showQuickJumper: true,
  showSizeChanger: true,
  total: 0,
  showTotal: (total, range) => {
    return `${range[0]}-${range[1]} 共 ${total} 条数据`
  },
  onChange: (page, pageSize) => {
    console.log('报警设置 > 报警邮件发送服务器 >>', page, pageSize)
  }
}

// 测试报警邮件发送服务器
const ceShiBaoJingYouJianFaSongFuWuQi = () => {
  Modal.confirm({
    title: '确认操作',
    icon: h(ExclamationCircleOutlined),
    content: '发送测试邮件?',
    okText: '确定',
    okType: 'danger',
    cancelText: '取消',
    onOk() {
      console.log('OK')
    },
    onCancel() {
      console.log('Cancel')
    }
  })
}
</script>

<style scoped lang='scss'>
.ant-row {
  margin-bottom: 10px;
}

.y-close-fuzhi-fuwu {
  color: red;
}
</style>